package com.ruoyi.base.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.base.domain.BaseSpecialty;
import com.ruoyi.base.service.IBaseSpecialtyService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("专业信息管理")
@RestController
@RequestMapping("/base/specialty")
public class BaseSpecialtyController extends BaseController
{
    @Autowired
    private IBaseSpecialtyService baseSpecialtyService;

    /**
     * 查询专业列表
     */
    @ApiOperation("获取专业列表")
    @PreAuthorize("@ss.hasPermi('base:specialty:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSpecialty baseSpecialty)
    {
        startPage();
        List<BaseSpecialty> list = baseSpecialtyService.selectBaseSpecialtyList(baseSpecialty);
        return getDataTable(list);
    }
    
    /**
     * 查询专业下拉列表
     */
    @ApiOperation("获取专业下拉列表")
    @GetMapping("/select")
    public TableDataInfo select(BaseSpecialty baseSpecialty)
    {
        List<BaseSpecialty> list = baseSpecialtyService.selectList(baseSpecialty);
        return getDataTable(list);
    }


    /**
     * 导出专业列表
     */
    @ApiOperation("导出专业列表")
    @PreAuthorize("@ss.hasPermi('base:specialty:export')")
    @Log(title = "专业", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseSpecialty baseSpecialty)
    {
        List<BaseSpecialty> list = baseSpecialtyService.selectBaseSpecialtyList(baseSpecialty);
        ExcelUtil<BaseSpecialty> util = new ExcelUtil<BaseSpecialty>(BaseSpecialty.class);
        return util.exportExcel(list, "specialty");
    }

    /**
     * 获取专业详细信息
     */
    @ApiOperation("获取专业详细信息")
    @ApiImplicitParam(name = "id", value = "专业ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:specialty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseSpecialtyService.selectBaseSpecialtyById(id));
    }

    /**
     * 新增专业
     */
    @ApiOperation("新增专业")
    @PreAuthorize("@ss.hasPermi('base:specialty:add')")
    @Log(title = "专业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSpecialty baseSpecialty)
    {
    	baseSpecialty.setCreateBy(SecurityUtils.getUsername());
    	baseSpecialty.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(baseSpecialtyService.insertBaseSpecialty(baseSpecialty));
    }

    /**
     * 修改专业
     */
    @ApiOperation("修改专业")
    @PreAuthorize("@ss.hasPermi('base:specialty:edit')")
    @Log(title = "专业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSpecialty baseSpecialty)
    {
    	baseSpecialty.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(baseSpecialtyService.updateBaseSpecialty(baseSpecialty));
    }

    /**
     * 删除专业
     */
    @ApiOperation("删除专业")
    @ApiImplicitParam(name = "id", value = "专业ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('base:specialty:remove')")
    @Log(title = "专业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSpecialtyService.deleteBaseSpecialtyByIds(ids));
    }
}
